# -*- coding: utf-8 -*-
"""
DAL层 文件上传.
"""
import DBLink.dbHelp

dbHelp = DBLink.dbHelp

# 添加---展厅图片
def _api_gallery_picture_add(_request):
    '''
           /api/gallery.picture.add
           功能：添加---展厅图片
           编写：zpp
            :param _request = {"RequestBaseHeader": {"SeesionKey": "", "TimeSpan": ""},"GalleryNum":"test","MainImg":"test","ImgMang":"test","MainType":1,"ImgName":"hehh"}
             :param _request["GalleryNum"]:展厅编号
                         :param _request["MainImg"]:图片路径
                         :param _request["ImgMang"]:图片备注
                         :param _request["MainType"]:图片类别，1主图，2副图
                         :param _request["ImgName"]:图片名称
           :return _respon ={"ErrorInfo": {"ErrorCode": 0, "ErrorMsg": ""}, "IsError": false, "ReturnValue": true}

    '''
    _respon = {"ErrorInfo": {"ErrorCode": "0", "ErrorMsg": ""}, "ReturnValue": "", "IsError": ""}
    objIdReturn = dbHelp.GetNewids("gallerypicturelist")
    if objIdReturn["Value"] == 0:
        _respon["IsError"] = objIdReturn["IsError"]
        _respon["ErrorInfo"]["ErrorCode"] = objIdReturn["ErrorCode"]
        _respon["ErrorInfo"]["ErrorMsg"] = objIdReturn["ErrorMsg"]
        _respon["ReturnValue"] = objIdReturn["ReturnValue"]
    else:
        strSqlB = """
             INSERT INTO gallerypicturelist
             (MainID,GalleryNum,MainImg,ImgMang,MainType,UploadTime,ImgName,IsUsing)
            VALUES(
            '""" + objIdReturn["Value"] + """',
           '""" + _request["GalleryNum"] + """',
            '""" + _request["MainImg"] + """',
           '""" + _request["ImgMang"] + """',
           """ + str(_request["MainType"]) + """,
            DATE_FORMAT(now(),'%Y-%m-%d %H:%i:%s'),
            '""" + str(_request["ImgName"]) + """',
            '1'
            )
             """
        objReturnB = dbHelp.Exec(strSqlB)
        _respon["IsError"] = objReturnB["IsError"]
        _respon["ErrorInfo"]["ErrorCode"] = objReturnB["ErrorCode"]
        _respon["ErrorInfo"]["ErrorMsg"] = objReturnB["ErrorMsg"]
        _respon["ReturnValue"] = objReturnB["ReturnValue"]
    return _respon


# 添加---类型对应商品图片
def _api_goodstype_type_picture_add(_request):
    '''
           /api/goodstype.type.picture.add
           功能：添加---类型对应商品图片
           编写：cgz
           :param _request ={"RequestBaseHeader": {"SeesionKey": "", "TimeSpan": ""}, "ImgMag": "测试描述", "GoodsTypeID": "1", "ImgPath": "image/222.img", "ImgName": "测试名称"}
           :param _request["ImgMag"]=图片描述
           :param _request["GoodsTypeID"]=类型ID
           :param _request["ImgPath"]=图片路径
           :param _request["ImgName"]=图片名称
           :return _respon ={"ErrorInfo": {"ErrorCode": 0, "ErrorMsg": ""}, "IsError": false, "ReturnValue": true}
    '''
    _respon = {"ErrorInfo": {"ErrorCode": "0", "ErrorMsg": ""}, "ReturnValue": "", "IsError": ""}
    objIdReturn = dbHelp.GetNewids("goodstypeimg")
    strSqlIn = """
        INSERT INTO goodstypeimg(
        ImgID,ImgMag,GoodsTypeID
        ,ImgPath,ImgName,IsUsing,UploadTime
        )
        VALUES
        (
        '""" + objIdReturn["Value"] + """',
       '""" + str(_request["ImgMag"]) + """',
        '""" + str(_request["GoodsTypeID"]) + """',
        '""" + str(_request["ImgPath"]) + """',
       '""" + str(_request["ImgName"]) + """',
        '1',
         DATE_FORMAT(now(),'%Y-%m-%d %H:%i:%s')
        )
    """
    ReturnSqlIn = dbHelp.Exec(strSqlIn)
    _respon["IsError"] = ReturnSqlIn["IsError"]
    _respon["ErrorInfo"]["ErrorCode"] = ReturnSqlIn["ErrorCode"]
    _respon["ErrorInfo"]["ErrorMsg"] = ReturnSqlIn["ErrorMsg"]
    _respon["ReturnValue"] = ReturnSqlIn["ReturnValue"]
    return _respon





def _api_img_up_byshop( cs_GalleryNum,cs_ImgPath,cs_ImgRemark,cs_ImgType ,cs_ImgName,cs_GoodsTypeID):
    '''
    上传并保存展厅对应的图片
    :param cs_GalleryNum:   展厅编号
    :param cs_ImgRemark:      图片备注
    :param cs_ImgType:     图片类型
    :param cs_ImgName:      图片名称
    :param cs_ImgPath:      图片路径
    :return:
    '''
    _respon = {"ErrorInfo": {"ErrorCode": "0", "ErrorMsg": ""}, "ReturnValue": "", "IsError": ""}

    objIdReturn = dbHelp.GetNewids("gallerypicturelist")
    if objIdReturn["Value"] == 0:
        _respon["IsError"] = objIdReturn["IsError"]
        _respon["ErrorInfo"]["ErrorCode"] = objIdReturn["ErrorCode"]
        _respon["ErrorInfo"]["ErrorMsg"] = objIdReturn["ErrorMsg"]
        _respon["ReturnValue"] = objIdReturn["ReturnValue"]
    else:

        strSqlB = """
                    INSERT INTO gallerypicturelist
                    (MainID,GalleryNum,ImgPath,ImgRemark,ImgType,UploadTime,ImgName,IsUsing,GoodsTypeID)
                   VALUES(
                   '""" + objIdReturn["Value"] + """',
                  '""" + str(cs_GalleryNum) + """',
                   '""" + str(cs_ImgPath) + """',
                  '""" + str(cs_ImgRemark) + """',
                  '""" + str(cs_ImgType) + """',
                   DATE_FORMAT(now(),'%Y-%m-%d %H:%i:%s'),
                   '""" + str(cs_ImgName) + """',
                   '1',
                   '"""+str(cs_GoodsTypeID)+"""'
                   )
                    """

        objReturnB = dbHelp.Exec(strSqlB)
        _respon["IsError"] = objReturnB["IsError"]
        _respon["ErrorInfo"]["ErrorCode"] = objReturnB["ErrorCode"]
        _respon["ErrorInfo"]["ErrorMsg"] = objReturnB["ErrorMsg"]
        _respon["ReturnValue"] = objReturnB["ReturnValue"]
    return _respon



def _api_img_up_bytype(cs_ImgRemark,cs_GoodsTypeID,cs_ImgName,cs_ImgPath):
    '''
    上传并保存产品类型对应的图片
    :param cs_ImgRemark:
    :param cs_GoodsTypeID:
    :param cs_ImgName:
    :param cs_ImgPath:
    :return:
    '''

    _respon = {"ErrorInfo": {"ErrorCode": "0", "ErrorMsg": ""}, "ReturnValue": "", "IsError": ""}
    objIdReturn = dbHelp.GetNewids("goodstypeimg")
    strSqlIn = """
            INSERT INTO goodstypeimg(
            ImgID,ImgRemark,GoodsTypeID
            ,ImgPath,ImgName,IsUsing,UploadTime
            )
            VALUES
            (
            '""" + objIdReturn["Value"] + """',
           '""" + str(cs_ImgRemark) + """',
            '""" + str(cs_GoodsTypeID) + """',
            '""" + str(cs_ImgPath) + """',
           '""" + str(cs_ImgName) + """',
            '1',
             DATE_FORMAT(now(),'%Y-%m-%d %H:%i:%s')
            )
        """
    ReturnSqlIn = dbHelp.Exec(strSqlIn)
    _respon["IsError"] = ReturnSqlIn["IsError"]
    _respon["ErrorInfo"]["ErrorCode"] = ReturnSqlIn["ErrorCode"]
    _respon["ErrorInfo"]["ErrorMsg"] = ReturnSqlIn["ErrorMsg"]
    _respon["ReturnValue"] = ReturnSqlIn["ReturnValue"]
    return _respon